package cn.xuqiudong.rpc.common.util;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;

/**
 * 描述:一些通用的个 工具方法
 * @author Vic.xu
 * @date 2022-03-04 11:49
 */
public class CommonUtils {

    private CommonUtils(){
        throw new IllegalStateException("Utility class");
    }

    /**
     * InputStream 转byte数组
     * @param input InputStream
     * @return  byte[]
     * @throws IOException
     */
    public static byte[] toByteArray(InputStream input) throws IOException {
        ByteArrayOutputStream output = new ByteArrayOutputStream();
        byte[] buffer = new byte[4096];
        int n = 0;
        while (-1 != (n = input.read(buffer))) {
            output.write(buffer, 0, n);
        }
        return output.toByteArray();
    }
}
